package com.geoserver.controller;

import com.geoserver.service.ImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * FileName: ImageController
 * Create by fengzheng on 2019/4/26 10:30
 * Description: 图片文件获取
 */

@Controller
public class ImageController {

    private ImageService imageService;

    @Autowired
    public ImageController(ImageService imageService) {
        this.imageService = imageService;
    }

    @GetMapping("/getImage")
    public void getImage(String imageAddress, int type, HttpServletResponse response){
        BufferedImage image = imageService.getImageStream(imageAddress,type);
        if(image != null){
            try {
                ImageIO.write(image,"JPEG",response.getOutputStream());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
